home *** CD-ROM | disk | FTP | other *** search
- Path: nntp-trd.UNINETT.no!usenet
- From: Paul Kenneth Egell-johnsen <paulken4@afrodite.kih.no>
- Newsgroups: comp.lang.c++
- Subject: Re: How do I put DIFFERENT classes in the same linked list?
- Date: Wed, 17 Apr 1996 19:12:36 +0200
- Organization: UNINETT news service
- Message-ID: <31752684.13CC@afrodite.kih.no>
- References: <4ka938$bj6@wintermute.ecs.fullerton.edu> <marnoldDpJ9HK.41D@netcom.com> <3173563E.16DF@esec.ch>
- NNTP-Posting-Host: afrodite.kih.no
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (X11; I; HP-UX A.09.05 9000/720)
-
- Oliver Plohmann wrote:
- >
- > > >I'm trying to write a program where I need to maintain a linked list of
- > > >various items. Each item is a class, but each item is different from another
- > > >item. Let me give an example to clarify:
- >
- > Hello,
- >
- > I haven't followed the thread whether using virtual functions will do want you were looking
- > for. But inserting instances of different classes into a parameterized linked list node is not
- > possible.
-
- My simple solution is, make all of your classes derived from
- another class (called universe in this example). Then make the
- linked list point to univers. Thereafter you can insert all the
- other classes (as they are derived from univers) into the linked
- list. Make the linked list derived from univers, then you have
- the possibility to have linked lists within the linked list,
- great for 'group' functions in an graphics editor, to use one
- example.
-
- If you make the linked list class a template class, then you can
- use all kinds of objects (even if they aren't derived of
- univers) in a linked list (but it has to be heterogenous ie.
- only objects of that type, or derived from it since we are
- speaking of C++).
-
- The specifics I think you have yourself.
-
- Paul K Egell-Johnsen,
-
- mailto:paulken4@afrodite.kih.no
- http://afrodite.kih.no:8001/studenter/paulken4/frames/
-